# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=netcdf
pkgver=4.9.2
pkgrel=3
pkgdesc="Libraries for the Unidata network Common Data Format"
url="https://www.unidata.ucar.edu/software/netcdf/"
# disabled on s390x because of https://github.com/Unidata/netcdf-c/issues/1987
arch="all !s390x"
license="BSD-3-Clause"
options="net"  # tests need network access
makedepends="
	bash
	bzip2-dev
	cmake
	curl-dev
	hdf5-dev
	libaec-dev
	libxml2-dev
	m4
	samurai
	"
subpackages="
	$pkgname-doc
	$pkgname-dev
	$pkgname-utils:utils
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/Unidata/netcdf-c/archive/v$pkgver.tar.gz
	fix-test-on-big-endian.patch
	"
builddir="$srcdir/$pkgname-c-$pkgver"

build() {
	local _enable_cdf5=ON
	case "$CARCH" in
		x86|armhf|armv7) _enable_cdf5=OFF ;;
	esac
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DCMAKE_BUILD_TYPE=None \
		-DENABLE_CDF5=$_enable_cdf5 \
		-DENABLE_DAP_LONG_TESTS=ON \
		-DENABLE_EXAMPLE_TESTS=ON \
		-DENABLE_EXTRA_TESTS=ON \
		-DENABLE_FAILING_TESTS=ON \
		-DENABLE_FILTER_TESTING=ON \
		-DENABLE_LARGE_FILE_TESTS=ON
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

utils() {
	amove usr/bin
}

check() {
	# One test failure in nc_test as reported in https://github.com/Unidata/netcdf-c/issues/808
	# Server test.opendap.org:8080 seems to be down for dap4_test_test_hyrax|dap4_test_test_thredds test
	# Tests have to be executed in the correct order
	# ncdap_tst_remote3: fails repeatedly on builder
	# ncdump_tst_netcdf4_4: https://github.com/Unidata/netcdf-c/issues/2616
	cd build
	CTEST_OUTPUT_ON_FAILURE=1 ctest -j 1 -E 'nc_test|dap4_test_test_hyrax|dap4_test_test_thredds|ncdump_test_rcmerge|ncdap_tst_remote3|ncdump_tst_netcdf4_4'
}

sha512sums="
e0c299843083cde54bfaccebd4f831513c2c531f3a98e37a1bc14d12a5e63af0b994cab9292bcb17e1b162ffe26b49ed3f9c6de7f2f48cdfcfd3f3c4a377bb04  netcdf-4.9.2.tar.gz
29dda7a0e28333afb91f948c1f5527606634ab8014c6f123e73b092e550d9514c45391f11b33c59cbfbb1fd1ff581848305a47d3768f9b4d1a2be63609009d82  fix-test-on-big-endian.patch
"
